import tabbarView from "view/tabbar.art";
import "styles/tabbar/index.scss";

class TabBar{
    constructor(){

        this.data=[
            {
                icon: "&#xec07;",
                text: "演出"
            },
            {
                icon: "&#xe788;",
                text: "周边"
            },
            {
                icon: "&#xe62b;",
                text: "众筹"
            },
            {
                icon: "&#xe611;",
                text: "我的"
            }
        ],
        this.activeIndex=0;
        this.router=window.router;
        console.log(this.router)
    }
    init(){
        this.render();

    }
    render(){
         var html=tabbarView({data:this.data})
         $("#app").append(html)
         this.eachTaBar();
    }
    eachTaBar(){
        this.ali=$("#footer>ul li");
        var hash=window.location.hash.slice(1);
        switch(hash){
            case "/":
                this.activeIndex = 0;
                break;
                case "/money":
                this.activeIndex = 1;
                break;
                case "/shop":
                this.activeIndex = 2;
                break;
                case "/mine":
                this.activeIndex = 3;
                break;
        }
        this.ali.eq(this.activeIndex).addClass("active").siblings().removeClass("active");
        this.ali.each(this.eachTaBarCb.bind(this))
    }
    eachTaBarCb(index){
        console.log(777777)
        this.ali.eq(index).on("tap", this.handleTabBarTap.bind(this, index))
    }
    handleTabBarTap(index) {
        switch (index) {
            case 0:
                router.push("/");
                break;
            case 1:
                router.push("/money");
                break;
            case 2:
                router.push("/shop");
                break;
            case 3:
                router.push("/mine");
                break;
        }
        this.ali.eq(index).addClass("active").siblings().removeClass("active");
    }
}

export default new TabBar;